

exports.rabbitmq = {
    async init(app,ctx){
        const {tortoise} = app;

        // console.log(tortoise);
        // rabbitmq
        // https://github.com/CompassPHS/tortoise
        // 订阅
        // tortoise
        //     .queue('my-queue')
        //     .prefetch(1)
        //     // .json()
        //     .subscribe(function (msg, ack) {
        //         console.log(msg);
        //         ack();
        //     });

        // exchange
        // 消费消息
        tortoise.queue('q1')
            //.queue('my-queue', { durable: false })
            // Add as many bindings as needed
            .exchange('eoa-exchange-direct', 'direct', 'formTo', { durable: false })
            .prefetch(1)
            .subscribe(function(msg, ack, nack) {
                console.log(`q1[队列] eoa-exchange-direct[交换器] direct[交换器类型] formTo[路由键] 载荷: ${msg}`);
                ack(); // or nack();
                // Handle 消息确认\
                tortoise
                    .exchange('eoa-exchange-direct', 'direct', { durable:false })
                    .publish('reply', { Hello: 'World'+new Date().getTime() });
            });



    },
    getExchangeDirectPublish(tortoise,queue,routeingKey){
        return tortoise.queue(queue).exchange('eoa-exchange-direct', 'direct', { durable: false })
    },
    getConsumer(tortoise,queue,routeingKey){
        return tortoise.queue(queue).exchange('eoa-exchange-direct', 'direct',routeingKey, { durable: false })
    }
};